﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Nacos.AspNetCore;
using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace Assets.API.Controllers
{
    public class ExportController : MvcControllerBase
    {
        private IHostingEnvironment _hostingEnvironment;
        private readonly INacosServerManager _serverManager;
        public ExportController(IHostingEnvironment hostingEnvironment, INacosServerManager serverManager) : base(serverManager)

        {

            _serverManager = serverManager;
            _hostingEnvironment = hostingEnvironment;

        }
        //[HttpGet]
        //[AllowAnonymous]
        //public async Task<FileResult>  ExportFinance(string org = "", string month = "", string endmonth = "", string sflh = "", string ss = "", string dwzt="", string type = "1")
        //{

        //    //HttpResponseMessage response = null;
            
        //        string fileName = "";
        //        //string orgs = await Getorg();
        //        //if (!org.Contains(orgs))
        //        //{
        //        //    org = orgs;
        //        //}

        //        DataTable table = null;
        //        if (month == null || month == "")
        //        {
        //            month = DateTime.Today.AddMonths(-2).ToString("yyyyMM");
        //        }
        //        switch (type)
        //        {
        //            case "1":
        //                fileName = "收支明细表";
        //                table = await BusinessRule.Warning.Waring.GetSZMXB(org, month, endmonth, sflh, ss,dwzt);
        //                break;
        //            case "2":
        //                fileName = "债务债权表";
        //                table = await BusinessRule.Warning.Waring.GetZWZQB(org, month, endmonth, sflh, ss, dwzt);
        //                break;
        //            case "3":
        //                fileName = "科目余额表";
        //                table = await BusinessRule.Warning.Waring.GetKMYEB(org, month, endmonth, sflh, ss, dwzt);
        //                break;
        //            case "4":
        //                fileName = "资产负债表";
        //                table = await BusinessRule.Warning.Waring.GetZCFZB(org, month, endmonth, sflh, ss, dwzt);
        //                break;
        //            case "5":
        //                fileName = "收益分配表";
        //                table = await BusinessRule.Warning.Waring.GetSYFPB(org, month, endmonth, sflh, ss, dwzt);
        //                break;
        //        }
        //        string str = APICommond.ImportExcel.CreateExcel(table);
        //        string filePath = AppContext.BaseDirectory + "DownLoad\\";
        //        if (!System.IO.Directory.Exists(filePath))
        //        {
        //            System.IO.Directory.CreateDirectory(filePath);
        //        }
        //        filePath = AppContext.BaseDirectory + "DownLoad\\" + fileName+".xls";
        //        if (System.IO.File.Exists(filePath))
        //        {
        //            System.IO.File.Delete(filePath);
        //        }

        //        FileStream st = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite);


        //        byte[] d = Encoding.UTF8.GetBytes(str);

        //        st.Write(d, 0, d.Length);
        //        st.Close();
               
        //        FileStream stream = new FileStream(filePath, FileMode.Open);
            
        //    var actionresult = new FileStreamResult(stream, new Microsoft.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream"));
        //    actionresult.FileDownloadName =fileName+".xls";
        //    return actionresult;

        //}


    }
}
